package com.illtamer.infinite.collapsar.dispatcher.smtp;

import com.illtamer.infinite.collapsar.dispatcher.EmailSender;
import com.sun.mail.smtp.SMTPTransport;
import lombok.SneakyThrows;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;

public class SMTPProxySender implements EmailSender {

    @Override
    @SneakyThrows({NoSuchProviderException.class, MessagingException.class})
    public void sendMessage(Message message) {
        Session session = message.getSession();
        try (SMTPTransport transport = (SMTPTransport) session.getTransport()) {
            transport.connect();
            transport.sendMessage(message, message.getAllRecipients());
        }
    }

}
